<template>
  <el-dialog
    :title="!dataForm.uid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="创建人uid" prop="createUserUid">
      <el-input v-model="dataForm.createUserUid" placeholder="创建人uid"></el-input>
    </el-form-item>
    <el-form-item label="创建人名称" prop="createUserName">
      <el-input v-model="dataForm.createUserName" placeholder="创建人名称"></el-input>
    </el-form-item>
    <el-form-item label="回复某条评论的uid" prop="toUid">
      <el-input v-model="dataForm.toUid" placeholder="回复某条评论的uid"></el-input>
    </el-form-item>
    <el-form-item label="回复某个人的uid" prop="toUserUid">
      <el-input v-model="dataForm.toUserUid" placeholder="回复某个人的uid"></el-input>
    </el-form-item>
    <el-form-item label="评论内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="评论内容"></el-input>
    </el-form-item>
    <el-form-item label="榜单成员uid" prop="momentUid">
      <el-input v-model="dataForm.momentUid" placeholder="榜单成员uid"></el-input>
    </el-form-item>
    <el-form-item label="榜单成员名称" prop="momentName">
      <el-input v-model="dataForm.momentName" placeholder="榜单成员名称"></el-input>
    </el-form-item>
    <el-form-item label="状态：0删除的 1激活的 2冻结的 3置顶的" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态：0删除的 1激活的 2冻结的 3置顶的"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="评论来源： MESSAGE_BOARD，ABOUT，BLOG_INFO 等" prop="source">
      <el-input v-model="dataForm.source" placeholder="评论来源： MESSAGE_BOARD，ABOUT，BLOG_INFO 等"></el-input>
    </el-form-item>
    <el-form-item label="评论类型 1:点赞 0:评论" prop="type">
      <el-input v-model="dataForm.type" placeholder="评论类型 1:点赞 0:评论"></el-input>
    </el-form-item>
    <el-form-item label="一级评论UID" prop="firstCommentUid">
      <el-input v-model="dataForm.firstCommentUid" placeholder="一级评论UID"></el-input>
    </el-form-item>
    <el-form-item label="审批状态【0：待审批，1：审核未通过，2：审核通过】" prop="auditStatus">
      <el-input v-model="dataForm.auditStatus" placeholder="审批状态【0：待审批，1：审核未通过，2：审核通过】"></el-input>
    </el-form-item>
    <el-form-item label="审批人" prop="auditName">
      <el-input v-model="dataForm.auditName" placeholder="审批人"></el-input>
    </el-form-item>
    <el-form-item label="审批拒绝原因" prop="rejectReason">
      <el-input v-model="dataForm.rejectReason" placeholder="审批拒绝原因"></el-input>
    </el-form-item>
    <el-form-item label="审批时间" prop="auditTime">
      <el-input v-model="dataForm.auditTime" placeholder="审批时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          uid: 0,
          createUserUid: '',
          createUserName: '',
          toUid: '',
          toUserUid: '',
          content: '',
          momentUid: '',
          momentName: '',
          status: '',
          createTime: '',
          updateTime: '',
          source: '',
          type: '',
          firstCommentUid: '',
          auditStatus: '',
          auditName: '',
          rejectReason: '',
          auditTime: ''
        },
        dataRule: {
          createUserUid: [
            { required: true, message: '创建人uid不能为空', trigger: 'blur' }
          ],
          createUserName: [
            { required: true, message: '创建人名称不能为空', trigger: 'blur' }
          ],
          toUid: [
            { required: true, message: '回复某条评论的uid不能为空', trigger: 'blur' }
          ],
          toUserUid: [
            { required: true, message: '回复某个人的uid不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '评论内容不能为空', trigger: 'blur' }
          ],
          momentUid: [
            { required: true, message: '榜单成员uid不能为空', trigger: 'blur' }
          ],
          momentName: [
            { required: true, message: '榜单成员名称不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态：0删除的 1激活的 2冻结的 3置顶的不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          source: [
            { required: true, message: '评论来源： MESSAGE_BOARD，ABOUT，BLOG_INFO 等不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '评论类型 1:点赞 0:评论不能为空', trigger: 'blur' }
          ],
          firstCommentUid: [
            { required: true, message: '一级评论UID不能为空', trigger: 'blur' }
          ],
          auditStatus: [
            { required: true, message: '审批状态【0：待审批，1：审核未通过，2：审核通过】不能为空', trigger: 'blur' }
          ],
          auditName: [
            { required: true, message: '审批人不能为空', trigger: 'blur' }
          ],
          rejectReason: [
            { required: true, message: '审批拒绝原因不能为空', trigger: 'blur' }
          ],
          auditTime: [
            { required: true, message: '审批时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.uid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.uid) {
            this.$http({
              url: this.$http.adornUrl(`/community/momentcomment/info/${this.dataForm.uid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.createUserUid = data.momentComment.createUserUid
                this.dataForm.createUserName = data.momentComment.createUserName
                this.dataForm.toUid = data.momentComment.toUid
                this.dataForm.toUserUid = data.momentComment.toUserUid
                this.dataForm.content = data.momentComment.content
                this.dataForm.momentUid = data.momentComment.momentUid
                this.dataForm.momentName = data.momentComment.momentName
                this.dataForm.status = data.momentComment.status
                this.dataForm.createTime = data.momentComment.createTime
                this.dataForm.updateTime = data.momentComment.updateTime
                this.dataForm.source = data.momentComment.source
                this.dataForm.type = data.momentComment.type
                this.dataForm.firstCommentUid = data.momentComment.firstCommentUid
                this.dataForm.auditStatus = data.momentComment.auditStatus
                this.dataForm.auditName = data.momentComment.auditName
                this.dataForm.rejectReason = data.momentComment.rejectReason
                this.dataForm.auditTime = data.momentComment.auditTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/community/momentcomment/${!this.dataForm.uid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'uid': this.dataForm.uid || undefined,
                'createUserUid': this.dataForm.createUserUid,
                'createUserName': this.dataForm.createUserName,
                'toUid': this.dataForm.toUid,
                'toUserUid': this.dataForm.toUserUid,
                'content': this.dataForm.content,
                'momentUid': this.dataForm.momentUid,
                'momentName': this.dataForm.momentName,
                'status': this.dataForm.status,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'source': this.dataForm.source,
                'type': this.dataForm.type,
                'firstCommentUid': this.dataForm.firstCommentUid,
                'auditStatus': this.dataForm.auditStatus,
                'auditName': this.dataForm.auditName,
                'rejectReason': this.dataForm.rejectReason,
                'auditTime': this.dataForm.auditTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
